﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ChequeManagement.BLL
{
    /// <summary>
    /// This Class contains number of Field,constructor , properties,method and this class inheritance of BaseObject class
    /// </summary>
    /// <field> this field use in IsValid method for set parameter ApplicationInfo class and properties</field>
    /// <properties>this properties contain set for receive value and contain get for return value </properties>
    ///  <method>this class contain IsValid method for Validation all properties</method>
    ///  <constructor>this class include a constructor that one not have overload</constructor>
    public class BLLChequeCategoryWithPARI : BaseObject
    {
        /// <summary>
        ///  This constructor not have parameter and use on create instance of class 
        /// </summary>
        public BLLChequeCategoryWithPARI()
        {
        }
        #region Fields

        private BLL.BLLChequeCategory chequeCategoryObject;
        private BLL.BLLPayAndReceiveItem payAndReceiveItemObject;

        //this filed is only for reading from database
        private int chequeCategoryID;
        private Int64 chequeNo;

        #endregion

        #region Properties

        /// <summary>
        /// This property contain set that check vlaue is null or not null if value not null, receive value  and contain get for return value
        /// </summary>
        public BLLChequeCategory ChequeCategoryObject
        {
            get
            {
                return chequeCategoryObject;
            }
            set
            {
                if (value != null)
                    chequeCategoryObject = value;
            }
        }

        /// <summary>
        /// This property contain set that check vlaue is null or not null if value not null, receive value  and contain get for return value
        /// </summary>
        public BLLPayAndReceiveItem PayAndReceiveItemObject
        {
            get
            {
                return payAndReceiveItemObject;
            }
            set
            {
                if (value != null)
                    payAndReceiveItemObject = value;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public int ChequeCategoryID
        {
            get
            {
                return chequeCategoryID;
            }
            set
            {
                chequeCategoryID = value;
            }
        }

        /// <summary>
        /// This property contain set for receive value and contain get for return value
        /// </summary>
        public Int64 ChequeNo
        {
            get
            {
                return chequeNo;
            }
            set
            {
                chequeNo = value;
            }
        }
        #endregion

        #region Methods

        /// <summary>
        ///This method check fields value
        ///this method check that if ChequeNo value is empty and ChequeCategoryID value is empty,add error
        /// </summary>
        /// <param name="excepts" Type="string[]"></param>
        /// <PayAndReceiveItemObject>PayAndReceiveItemObject is instance of BLLPayAndReceiveItem class that contain ChequeNo property</PayAndReceiveItemObject>
        /// <ChequeCategoryObject>ChequeCategoryObject is instance of BLLChequeCategory class that contain ChequeCategoryID property</ChequeCategoryObject>
        /// <returns>if all field is Valid,ErrorsCount value is zero and return true else ErrorsCount value Larger of zero and return false</returns>
        public bool IsValid(params string[] excepts)
        {
            if (PayAndReceiveItemObject.ChequeNo.ToString() == string.Empty && ChequeCategoryObject.ChequeCategoryID.ToString() == string.Empty)
                AddError("شماره دسته چک و شماره چک خالی است", null);
            else
            {
                //if (BankName.Length > 100)
                //    AddError("طول عنوان بانک نباید بیشتر از {0} کاراکتر باشد", 100);
                //if (excepts.Contains("BankName") == false)
                //{
                //    string command = "[" + tableName + "].[" + BankField.BankName.ToString() + "] = N'" + BankName + "'";
                //    Common.ApplicationInfo appInfo = new Common.ApplicationInfo(tableName);
                //    System.Data.DataTable dataSource = new System.Data.DataTable();

                //    object businessFactory = Activator.CreateInstance(Type.GetType(appInfo.BusinessLogicLayer));
                //    Common.PDController.DoInvokeMember(businessFactory, new object[] { command, dataSource }, new string[] { "condition", "dataTable" });
                //    if (dataSource != null && dataSource.Rows.Count > 0)
                //        AddError("عنوان بانک <{0}> از قبل موجود میباشد", BankName);
                //}
            }
            if (ErrorsCount > 0)
                return false;
            else
                return true;
        }

        #endregion
    }
}
